home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
oper_sys
/
oasis
/
oasis1-1.lha
/
oasis-1.1
/
par.y
< prev
next >
Wrap
Text File
|
1992-05-01
|
46KB
|
834 lines
/*==========================================================================*
Oasis Alpha Version 1.1 (C) Copyright 1992 Fah-Chun Cheong
Revised: 5/1/92 by: fcc@eecs.umich.edu and The University of Michigan
------------------------------------------------------------------------
Permission to use, copy, modify, distribute, sell and resell Oasis Alpha
software and its documentation for any purpose and without fee is hereby
granted, provided that the authorship be appropriately credited and
acknowledged, and that the above copyright notice appear in all copies
and both the copyright notice and this permission notice appear in
supporting documentation. The author makes no representations about the
suitability of this software for any purpose. It is provided "as is"
without express or implied warranty. Oasis Alpha is free, caveat emptor!
------------------------------------------------------------------------
To request Oasis Alpha source code: oasis-alpha-request@eecs.umich.edu
To enroll in the mailing list: oasis-alpha-request@eecs.umich.edu
To send bug reports: oasis-alpha-bugs@eecs.umich.edu
To discuss openly all matters Oasis: oasis-alpha@eecs.umich.edu
*==========================================================================*/
%{
#include "parser.h"
Type *Top;
Type *Bot;
Type *Int;
Type *Real;
Type *Char;
Type *Condv;
Node *Izero;
Node *Rzero;
Node *Blank;
Node *Nil;
Node *Anon;
Node *Self;
Node *Site;
Spec *specs;
Imp *imps;
Goal *goal;
Att *Atts0;
static int *_;
static int level;
static int kind;
static int prot;
static int step;
static int flow;
static int goff;
static int coff;
static int aoff;
static int moff;
static int size;
static Spec *base;
static Gene *genes, *gs;
static Cond *conds;
static Cst *csts;
static Att *atts0, *atts, *as;
static Met *mets, *ms;
static Arg *args0, *args;
static Rule *rules;
static Pred *last;
static Dim *dims;
static Var *vars;
static Node *self;
static Type *type, *t;
%}
%union {
int i;
double f;
char c;
char *s;
Spec *spec;
Gene *gene;
Cond *cond;
Att *att;
Met *met;
Arg *arg;
Type *type;
Con *con;
Dim *dim;
Imp *imp;
Rule *rule;
Head *head;
Clu *clu;
Pred *pred;
Var *var;
Par *par;
Prop *prop;
Node *node;
struct {
Dim *dims;
int size;
Prop *props;
Node *node;
Type *type;
} ary;
struct {
Dim *dims;
Type *type;
} idx;
struct {
Type *t;
int size;
Att *atts;
Type *type;
} inst;
struct {
Node *node;
int cost;
} exp;
}
%token CLASS CONSTANT ATTRIBUTE METHOD
%token PUBLIC PROTECTED PRIVATE
%token INT REAL CHAR
%token SELF NIL
%token DOT DO ISA IF THEN
%token EQ NE GT GE LT LE
%token <s> ID CID SID
%token <s> ATINET
%token <i> INTEGER
%token <f> FLOAT
%token <s> CHARACTER
%token <s> STRING
%type <clu> goal
%type <s> header
%type <s> cid
%type <s> id
%type <gene> genes
%type <gene> gene
%type <s> attid
%type <arg> arguments
%type <arg> argument
%type <arg> args
%type <arg> arg
%type <s> argid
%type <con> types0
%type <con> types
%type <type> type
%type <dim> dimensions
%type <i> dimension
%type <s> identifier
%type <rule> rules
%type <rule> rule
%type <rule> clause
%type <head> head
%type <clu> body
%type <pred> cluster
%type <pred> messages
%type <pred> message
%type <pred> predicate
%type <node> destination
%type <pred> primitive
%type <pred> matching
%type <pred> comparison
%type <node> rhs
%type <node> lhs
%type <i> relop
%type <par> parameters0
%type <par> parameters
%type <par> parameter
%type <node> value
%type <node> pvalue
%type <node> lvalue
%type <node> gvalue
%type <node> rvalue
%type <node> instance
%type <node> list
%type <node> null
%type <type> l2
%type <prop> elements
%type <node> element
%type <node> array
%type <node> string
%type <idx> l3
%type <ary> sizes_l3
%type <ary> sizes
%type <ary> size
%type <ary> l5
%type <node> items0
%type <node> items
%type <node> item
%type <node> component
%type <ary> l6
%type <node> handle
%type <node> atsite0
%type <node> atsite
%type <node> agent
%type <node> object
%type <inst> l1
%type <prop> properties0
%type <prop> properties
%type <prop> property
%type <node> global
%type <node> local
%type <node> varid
%type <node> refid
%type <node> accessors
%type <node> accessor
%type <dim> l0
%type <prop> indices
%type <node> index
%type <node> expression
%type <node> expression2
%type <exp> expr
%type <exp> term
%type <exp> factor
%type <exp> expr2
%type <exp> term2
%type <exp> factor2
%type <exp> expr1
%type <exp> term1
%type <exp> factor1
%type <i> addop
%type <i> mulop
%type <node> literal
%type <node> self
%type <node> nil
%%
start : { lineno = 1;
fname = NUL;
kind = AGENT;
self = Self;
level = 0;
conds = NUL;
csts = NUL;
mets = NUL;
atts0 = Atts0; }
goal '.' {}
| sections {}
;
goal : DO { check_agent(kind);
type = Top;
flow = OUT;
vars = NUL;
step = BODY; }
body { goal = Goal_(atts0, vars, $3); }
;
sections : sections section {}
| section {}
;
section : '#' INTEGER STRING { lineno = $2;
fname = $3; }
| specification {}
| implementation {}
;
specification : header { aoff = aoff > 0 ? aoff : goff;
atts0 = NUL;
self = Self; }
'{' declarations0 '}' { specs = Spec_($1, Soff(specs), level, aoff, base,
genes, conds, csts, atts, mets, specs); }
;
header : CLASS isa0 cid conditions0 { $$ = $3; }
| CID isa cid conditions0 { $$ = $3; }
| CLASS isa0 id generics0 { $$ = $3; }
| ID isa id generics0 { $$ = $3; }
;
isa : ISA { search_spec($<s>0, specs, &level, &aoff, &base,
&gs, &conds, &csts, &atts, &mets);
level++; }
;
isa0 : empty { level = 0;
aoff = 0;
base = NUL;
gs = NUL;
conds = NUL;
csts = NUL;
atts = NUL;
mets = NUL; }
;
cid : CID { $$ = $1; goff = 4; }
;
id : ID { $$ = $1; goff = 1; }
;
generics0 : { clash_spec($<s>0, specs);
genes = NUL;
prot = PROTECTED; }
genes0 { count_genes(gs); }
;
genes0 : LT genes GT {}
| empty {}
;
genes : genes ',' gene { $$ = $1->next = $3; }
| gene { $$ = genes = $1; }
;
gene : SID { clash_gene($1, genes);
check_gene(gs, level, $1);
count_gene(gs, level, $1);
gs = gs ? gs->next : NUL;
$$ = Gene_($1, goff++, NUL); }
;
conditions0 : '[' conditions ']' {}
| empty {}
;
conditions : conditions ',' condition {}
| condition {}
| error {}
;
condition : SID { clash_cond($1, conds);
conds = Cond_($1, Coff(conds), conds); }
;
declarations0 : constants attributes methods {}
| constants attributes {}
| constants methods {}
| attributes methods {}
| constants {}
| attributes {}
| methods {}
| empty {}
;
constants : constants constant {}
| CONSTANT ':' constant {}
;
constant : type { type = $1; }
consts ';' {}
| error ';' {}
;
consts : consts ',' const {}
| const {}
;
const : attid '=' expr { check_ref($3.node, BODY, IN, type);
csts = Cst_($1, $3.node, csts); }
;
attributes : attributes attribute {}
| ATTRIBUTE ':' attribute {}
;
attribute : protection type { type = $2; }
atts ';' {}
| error ';' {}
;
atts : atts ',' att {}
| att {}
;
att : attid '=' { vars = NUL;
step = BODY;
flow = IN; }
rvalue { atts = Att_($1, aoff++, level, prot, type, $4, atts); }
| attid { atts = Att_($1, aoff++, level, prot, type, null(type), atts); }
;
attid : ID { clash_cst($1, csts);
clash_att($1, level, atts);
$$ = $1; }
;
methods : methods method {}
| METHOD ':' method {}
;
method : protection ID { clash_met($2, level, mets);
args0 = args = NUL; }
'(' arguments0 ')' '.' { mets = Met_($2, Moff(mets), level, prot, args0, mets); }
| error ';' {}
;
arguments0 : arguments {}
| empty {}
;
arguments : arguments ';' argument { $1->next = args;
$$ = $3; }
| argument { args0 = args;
$$ = $1; }
;
argument : type { type = $1; }
args { $$ = $3; }
;
args : args ',' arg { $$ = $1->next = $3; }
| arg { $$ = args = $1; }
;
arg : argid { $$ = Arg_($1, IN, type, NUL); }
| '?' argid { $$ = Arg_($2, OUT, type, NUL); }
;
argid : CID { clash_arg($1, args);
clash_arg($1, args0);
$$ = $1; }
;
protection : PUBLIC { prot = PUBLIC; }
| PROTECTED { prot = PROTECTED; }
| PRIVATE { prot = PRIVATE; }
| empty {}
;
types0 : LT types GT { $$ = $2; }
| empty { $$ = NUL; }
;
types : type ',' types { $$ = Con_($1, $3); }
| type { $$ = Con_($1, NUL); }
;
type : SID { search_gene($1, genes, &goff);
$$ = Type_(META, goff); }
| type '*' { $$ = Type_(LIST, $1); }
| type '[' dimensions ']' { $$ = Type_(ARRAY, Array_($1, $3)); }
| ID types0 { $$ = Type_(OBJECT, Class_($1, $2)); }
| CID { $$ = Type_(AGENT, Class_($1, NUL)); }
| INT { $$ = Int; }
| REAL { $$ = Real; }
| CHAR { $$ = Char; }
;
dimensions : dimension ',' dimensions { $$ = Dim_($1, $3); }
| dimension { $$ = Dim_($1, NUL); }
;
dimension : expr { check_dim($1.node);
$$ = $1.node->this.i; }
| '_' { $$ = 0; }
;
implementation : identifier { search_spec($1, specs, &level, &_, &base,
&genes, &conds, &csts, &atts0, &mets);
clash_imp($1, imps);
t = Type_(kind, Class_($1, make_cons(genes)));
self = Node_p(SELF, t, NUL, NUL);
goal = NUL;
rules = NUL; }
'{' definitions0 '}' { imps = Imp_($1, base, goal, rules, imps); }
;
identifier : CID { $$ = $1; kind = AGENT; }
| ID { $$ = $1; kind = OBJECT; }
;
definitions0 : goal '.' rules '.' {}
| goal '.' {}
| rules '.' {}
| empty {}
;
rules : rules '.' rule { $$ = $1 ? ($1->next = $3) : (rules = $3); }
| rule { $$ = rules = $1; }
| error { $$ = NUL; }
;
rule : clause { check_vars(vars);
$$ = $1; }
;
clause : head IF body THEN body { $$ = Rule_(vars, $1, $3, $5, last, NUL); }
| head IF body { $$ = Rule_(vars, $1, $3, NUL, last, NUL); }
| head THEN body { $$ = Rule_(vars, $1, NUL, $3, last, NUL); }
| head { $$ = Rule_(vars, $1, NUL, NUL, last, NUL); }
;
head : ID { search_met($1, level, PROTECTED, mets, &moff, &prot, &args);
clash_head($1, rules, rules ? $<rule>-1 : NUL);
vars = NUL;
step = HEAD; }
'(' parameters0 _l4 { update_vars(vars);
step = BODY;
last = NUL;
$$ = Head_($1, moff, prot, $4); }
;
body : cluster ';' body { $$ = Clu_($1, step, $3); }
| cluster { $$ = Clu_($1, step, NUL); }
;
cluster : messages { update_vars(vars);
step += NEXT;
type = Top;
flow = OUT;
$$ = $1; }
;
messages : message { check_remote($1->tag);
undo_vars(vars); }
',' messages { $1->next = $4;
$$ = $1; last = NUL; }
| message { $$ = $1; last = NUL; }
| predicate { $$ = $1; last = $1; }
| primitive { $$ = $1; last = NUL; }
;
message : destination { char *name = ref_class($1->type);
search_spec(name, specs, &$<i>$, &size, &_,
&gs, &_, &_, &_, &ms);
if ($1->tag == HANDLE) $1->this.i = size; }
'!' ID { search_met($4, ($<i>2)+1, PUBLIC, ms, &moff, &_, &args);
args = subs_args(args, gs, get_cons($1->type)); }
'(' parameters0 _l4 { $$ = Pred_($1->type->tag == AGENT ? SEND
: $1->type->tag == OBJECT ? INVK
: same($4, "wait") ? WAIT : POST,
moff, $7, $1, NUL); }
;
predicate : identifier { search_base($1, base, &$<i>$, &ms); }
ISA ID { search_met($4, $<i>2, PROTECTED, ms, &moff, &_, &args); }
'(' parameters0 _l4 { $$ = Pred_(CALL, moff, $7, $1, NUL); }
| ID { search_met($1, level, PROTECTED, mets, &moff, &_, &args); }
'(' parameters0 _l4 { $$ = Pred_(CALL, moff, $4, NUL, NUL); }
;
destination : handle { $$ = $1; }
| global { $$ = $1; }
| local { $$ = $1; }
| self { $$ = $1; }
| SID { search_cond($1, conds, &coff);
$$ = Node_i(COND, Condv, coff, NUL); }
;
_l4 : { count_pars(args); }
')' { type = Top;
flow = OUT; }
;
primitive : matching { $$ = $1; }
| comparison { $$ = $1; }
;
matching : '(' type ')' { type = $2;
flow = OUT; }
value '=' { flow = IN; }
rvalue { $$ = Pred_(RELOP, IS, $8, $5, NUL); }
| gvalue '=' { type = $1->type;
flow = IN; }
rvalue { $$ = Pred_(RELOP, IS, $4, $1, NUL); }
;
comparison : lhs relop rhs { $$ = eval_relop($1, $2, $3); }
;
rhs : expression2 { $$ = $1; }
| lhs { $$ = $1; }
;
lhs : global { $$ = $1; }
| local { $$ = $1; }
| literal { $$ = $1; }
| self { $$ = $1; }
| nil { $$ = $1; }
| null { $$ = $1; }
;
relop : EQ { $$ = EQ; }
| NE { $$ = NE; }
| LT { $$ = LT; }
| LE { $$ = LE; }
| GT { $$ = GT; }
| GE { $$ = GE; }
;
parameters0 : parameters { $$ = $1; }
| empty { $$ = NUL; }
;
parameters : parameter ',' parameters { $1->next = $3;
$$ = $1; }
| parameter { $$ = $1; }
;
parameter : { count_par(args);
type = args ? args->type : Top;
flow = args ? args->flow : NUL; }
value { args = args ? args->next : NUL;
$$ = Par_(flow, $2, NUL); }
;
value : lvalue { $$ = $1; }
| rvalue { $$ = $1; }
| '_' { $$ = isin(step, flow) ? null(type) : Anon; }
;
pvalue : lvalue { $$ = $1; }
| rvalue { $$ = $1; }
| '_' { $$ = isin(step, flow) ? atts->init : Anon; }
;
lvalue : varid prime ':' value { $$ = Node_p(AS, $4->type, $4, $1);
check_lvar($1, step, flow, $4->type); }
| varid prime { check_lvar($1, step, flow, type); $$ = $1; }
| gvalue { check_lref($1, step, flow, type); $$ = $1; }
;
gvalue : global prime ':' value { $$ = Node_p(AS, $1->type, $4, $1); }
| global prime { $$ = $1; }
;
rvalue : expression2 { check_ref($1, step, flow, type); $$ = $1; }
| global { check_ref($1, step, flow, type); $$ = $1; }
| varid { check_var($1, step, flow, type); $$ = $1; }
| literal { check_ref($1, step, flow, type); $$ = $1; }
| self { check_ref($1, step, flow, type); $$ = $1; }
| nil { check_nil(type); $$ = $1; }
| instance { $$ = $1; }
;
instance : list { $$ = $1; if (isout(step, flow)) flip($1->tag); }
| array { $$ = $1; }
| string { $$ = $1; }
| handle { $$ = $1; }
| agent { $$ = $1; }
| object { $$ = $1; }
;
list : l2 elements '|' { type = $1; }
value ']' { $$ = Node_p(LIST, type = $1, $2, $5); }
| l2 elements ']' { $$ = Node_p(LIST, type = $1, $2, NUL); }
| l2 ']' { $$ = Node_p(LIST, type = $1, NUL, NUL); }
;
null : '[' ']' { $$ = Node_p(LIST, type, NUL, NUL); }
;
l2 : '[' { $$ = type; type = get_elem(type); }
;
elements : element ',' elements { $$ = Prop_($1, $3); }
| element { $$ = Prop_($1, NUL); }
;
element : value { $$ = $1; }
;
array : l3 '[' sizes_l3 l5 items0 _l5 { $$ = Node_p(ARRAY, $3.type, $3.node, $5); }
| l3 '[' sizes_l3 { $$ = Node_p(ARRAY, $3.type, $3.node, NUL); }
;
string : STRING { t = Type_(ARRAY, Array_(Char, Dim_(strlen($1), NUL)));
$$ = Node_p(STRING, t, $1, NUL);
check_string($1, t, type); }
;
l3 : '$' { $$.dims = dims; dims = get_dims(type);
$$.type = type; type = Int; }
;
sizes_l3 : sizes { count_sizes(dims); }
']' { dims = $<idx>-1.dims;
type = $<idx>-1.type;
$$.dims = $1.dims;
$$.type = Type_(ARRAY, Array_(get_item(type), $1.dims));
$$.node = Node_i(DOPE, $$.type, $1.size, $1.props);
if (isout(step, flow)) flip($$.node->tag); }
;
sizes : size ',' sizes { $$.props = Prop_($1.node, $3.props);
$$.dims = Dim_($1.size, $3.dims);
$$.size = $1.size * $3.size; }
| size { $$.props = Prop_($1.node, NUL);
$$.dims = Dim_($1.size, NUL);
$$.size = $1.size; }
;
size : { count_size(dims); }
value { check_size($2, step, flow, dims);
$$.size = grab_size($2, dims);
$$.node = $2;
dims = dims ? dims->next : NUL; }
;
l5 : '{' { $$.dims = dims; dims = $<ary>0.dims;
$$.size = size; size = dims->size;
$$.type = type; type = get_item(type); }
;
_l5 : { count_items(size); }
'}' { dims = $<ary>-1.dims;
size = $<ary>-1.size;
type = $<ary>-1.type; }
;
items0 : empty items { $$ = $<node>1; }
;
items : items ',' item { $$ = $1->that = $3; }
| item { $$ = $<node>0 = $1; }
;
item : { count_item(size--); }
component { $$ = $2; }
;
component : { count_dim(dims); }
l6 items0 _l6 { $$ = Node_i(ITEM, type, $3, NUL); }
| { count_dims(dims); }
value { $$ = Node_i(ITEM, type, $2, NUL); }
;
l6 : '{' { $$.dims = dims; dims = dims ? dims->next : NUL;
$$.size = size; size = dims ? dims->size : -1; }
;
_l6 : { count_items(size); }
'}' { dims = $<ary>-1.dims;
size = $<ary>-1.size; }
;
handle : CID { t = Type_(AGENT, Class_($1, NUL));
check_handle(t, type);
search_spec($1, specs, &_, &$<i>$, &_,
&gs, &_, &_, &as, &_); }
atsite { $$ = Node_i(HANDLE, t, $<i>2, $3); }
;
atsite0 : atsite { $$ = $1; }
| empty { $$ = Site; }
;
atsite : ATINET ':' INTEGER { $$ = Node_p(SITE, Bot, $1, (Node *) $3); }
| ATINET { $$ = Node_p(SITE, Bot, $1, (Node *) 0); }
;
agent : CID { check_name($1, get_agent(type)); }
l1 properties0 _l1 atsite0 { $$ = Node_p(AT, t, Node_p(AGENT, t, $3.size, $4), $6); }
;
object : ID { check_name($1, get_object(type)); }
l1 properties0 _l1 { $$ = Node_p(OBJECT, t, $3.size, $4); }
;
l1 : { search_spec($<s>-1, specs, &_, &$$.size, &_,
&gs, &_, &_, &as, &_); }
'{' { $$.t = Type_(type->tag, Class_($<s>-1, get_cons(type)));
$$.atts = atts; atts = subs_ratts(as, gs, get_cons(type));
$$.type = type; }
;
_l1 : { count_props(atts); }
'}' { t = $<inst>-1.t;
atts = $<inst>-1.atts;
type = $<inst>-1.type; }
;
properties0 : empty properties { $$ = $<prop>1;
atts = next_atts(atts, isin(step, flow), &$2->next, &_); }
| empty { atts = next_atts(atts, isin(step, flow), &$$, &_); }
;
properties : properties ',' property { $1->next = $<prop>2;
$$ = $3; }
| property { $$ = $1; }
;
property : { atts = next_atts(atts, isin(step, flow), &$<prop>0, &$<prop>$);
type = atts ? atts->type : Top;
count_prop(atts); }
pvalue { $$ = Prop_($2, NUL);
if (!$<prop>0) $<prop>0 = $$;
else $<prop>1->next = $$;
atts = atts ? atts->next : NUL; }
;
prime : '\'' { check_lvalue($<node>0->tag);
flip($<node>0->tag); }
;
global : local accessors { $1->that = $2;
$1->type = t;
$$ = $1; }
| refid accessors { $1->that = $2;
$1->type = t;
$$ = $1; }
| refid { $$ = $1; }
;
local : varid { check_bound($1, step, flow);
$$ = $1; }
;
varid : CID { Var *var = find_var($1, vars);
if (!var) var = vars =
Var_($1, 0, FF, UNDEF, UNDEF, type, type, type, vars);
$$ = Node_p(VAR, var->mint, var, NUL); }
;
refid : ID { if (self == Self && xxchar == '\'') {
aoff = Aoff(atts0); t = type;
atts0 = Att_($1, aoff, level, PROTECTED, t, null(t), atts0);
$$ = Node_i(REF, type, aoff, NUL);
}
else {
Cst *cst = find_cst($1, csts);
if (!cst) search_att($1, level, PROTECTED, atts0, &aoff, &t);
$$ = cst ? cst->node : Node_i(REF, t, aoff, NUL);
}}
;
accessors : accessor accessors { $1->that = $2;
$$ = $1; }
| accessor { $$ = $1; }
;
accessor : { char *name = ref_object($<node>0->type);
search_spec(name, specs, &$<i>$, &_, &_,
&gs, &_, &_, &as, &_); }
DOT ID { search_att($3, ($<i>1)+1, PUBLIC, as, &aoff, &t);
t = subs_type(t, gs, get_cons($<node>0->type));
$$ = Node_i(FIELD, t, aoff, NUL); }
| l0 indices _l0 { t = get_item($<node>0->type);
$$ = Node_p(INDEX, t, $2, NUL); }
;
l0 : '[' { $$ = dims; dims = ref_dims($<node>0->type); }
;
_l0 : { count_indices(dims); }
']' { dims = $<dim>-1; }
;
indices : index ',' indices { $$ = Prop_($1, $3); }
| index { $$ = Prop_($1, NUL); }
;
index : { count_index(dims); }
expression { check_index($2, dims);
dims = dims ? dims->next : NUL;
$$ = $2; }
;
expression : expr { $$ = Node_p(EXPR, $1.node->type, $1.node, NUL); }
;
expression2 : expr2 { $$ = Node_p(EXPR, $1.node->type, $1.node, NUL); }
;
expr : expr2 { $$.node = $1.node;
$$.cost = $1.cost; }
| expr1 { $$.node = $1.node;
$$.cost = $1.cost; }
;
term : term2 { $$.node = $1.node;
$$.cost = $1.cost; }
| term1 { $$.node = $1.node;
$$.cost = $1.cost; }
;
factor : factor2 { $$.node = $1.node;
$$.cost = $1.cost; }
| factor1 { $$.node = $1.node;
$$.cost = $1.cost; }
;
expr2 : expr addop term { $$.node = eval_arop($1.node, $2, $3.node);
$$.cost = eval_cost($1.cost, $$.node, $3.cost); }
| term2 { $$.node = $1.node;
$$.cost = $1.cost; }
;
term2 : term mulop factor { $$.node = eval_arop($1.node, $2, $3.node);
$$.cost = eval_cost($1.cost, $$.node, $3.cost); }
| factor2 { $$.node = $1.node;
$$.cost = $1.cost; }
;
factor2 : ID '(' expr ')' { $$.node = eval_fun($1, $3.node);
$$.cost = $3.cost; }
| '-' factor { $$.node = eval_uminus($2.node);
$$.cost = $2.cost; }
| '(' expr ')' { $$.node = $2.node;
$$.cost = $2.cost; }
;
expr1 : term1 { $$.node = $1.node;
$$.cost = $1.cost; }
;
term1 : factor1 { $$.node = $1.node;
$$.cost = $1.cost; }
;
factor1 : local { check_num($1); $$.node = $1; $$.cost = 1; }
| global { check_num($1); $$.node = $1; $$.cost = 1; }
| INTEGER { $$.node = Node_i(INT, Int, $1, NUL); $$.cost = 0; }
| FLOAT { $$.node = Node_f(REAL, Real, $1, NUL); $$.cost = 0; }
;
addop : '+' { $$ = ADD; }
| '-' { $$ = SUB; }
;
mulop : '*' { $$ = MUL; }
| '/' { $$ = DIV; }
| '%' { $$ = REM; }
;
literal : INTEGER { $$ = Node_i(INT, Int, $1, NUL); }
| FLOAT { $$ = Node_f(REAL, Real, $1, NUL); }
| CHARACTER { $$ = Node_p(CHAR, Char, $1, NUL); }
;
self : SELF { check_self(self);
$$ = self; }
;
nil : NIL { $$ = Node_p(NIL, type, NUL, NUL); }
;
empty : {}
;
%%
void init_par()
{
Top = Type_(TOP, Class_("$top", NUL));
Bot = Type_(BOT, Class_("$bot", NUL));
Int = Type_(INT, Class_("int", NUL));
Real = Type_(REAL, Class_("real", NUL));
Char = Type_(CHAR, Class_("char", NUL));
Condv = Type_(COND, Class_("$cond", NUL));
Izero = Node_i(INT, Int, 0, NUL);
Rzero = Node_f(REAL, Real, (float) 0.0, NUL);
Blank = Node_p(CHAR, Char, " ", NUL);
Nil = Node_p(NIL, Bot, NUL, NUL);
Anon = Node_p(ANON, Bot, NUL, NUL);
Self = Node_p(SELF, Bot, NUL, NUL);
Site = Node_i(SITE, Bot, "0", 0);
specs = Spec_("$cond", 1, 0, 0, NUL, NUL, NUL, NUL, NUL,
Met_("post", 1, 0, PUBLIC, Arg_("", IN, Int, NUL),
Met_("wait", 0, 0, PUBLIC, Arg_("", IN, Int, NUL), NUL)), NUL);
imps = NUL;
Atts0 = NUL;
}
void parse(buf, linesz)
char *buf;
int linesz;
{
init_lex(buf, linesz);
xxparse();
}